package limeirafol.gui.estoque;

import limeirafol.Global;
import limeirafol.remote.cadastro.AcessorioVO;
import limeirafol.bean.BeanEstoque;
import limeirafol.gui.Cadastro.AcessorioConsultaGUI;
import limeirafol.gui.MenuGUI;
import limeirafol.gui.ParametroGUI;
import limeirafol.remote.cadastro.tipoEmbalagem;
import limeirafol.remote.estoque.EstoqueAcessorioVO;
import limeirafol.remote.estoque.tipoOperacao;
import org.openide.util.Exceptions;
import lbframework.bean.consultaCampo.LBConsultaCampo;
import lbframework.bean.internalFrame.LBInternalFrame;
import lbframework.bean.mdiFrame.LBMdiFrame;
import lbframework.classe.Util;
import lbframework.classe.LBException;

public class EstoqueAcessorioCadastroGUI extends LBInternalFrame {

    public AcessorioVO oAcessorio = new AcessorioVO();
    public BeanEstoque beanEstoque = new BeanEstoque();
    EstoqueAcessorioVO oEstoque = new EstoqueAcessorioVO();

    public EstoqueAcessorioCadastroGUI(LBMdiFrame i_mdiFrame) throws Exception {
        super(i_mdiFrame);

        initComponents();

        centralizarForm();

        cnsAcessorio.setTabela("acessorios");
        cnsAcessorio.addRetorno("id_tipoembalagem", LBConsultaCampo.INT);
        cnsAcessorio.addRetorno("precounitario", LBConsultaCampo.DOUBLE);
        //pegar valor do retorno
        //  cboEstado.setId(cnsAcessorio.getInt("id_tipoembalagem"));

        cboTipoOperacao.setTabela("tipooperacaoestoque");
        cboTipoOperacao.carregar();

        cboTipoEmbalagem.setTabela("tipoembalagem");
        cboTipoEmbalagem.carregar();
        cboTipoEmbalagem.setId(-1);
        cboTipoEmbalagem.setEnabled(false);

        txtPrecoVenda.setEnabled(false);
        txtPrateleira.setEnabled(false);

        txtData.setText(Global.getDataProcessamento());
        txtData.setEnabled(false);

    }

    @Override
    public void salvar() throws Exception {
        Util.validarCampoTela(this.getCampoObrigatorio());

        oEstoque.data = Util.formatDataBanco(txtData.getText());
        oEstoque.id_tipoOperacao = cboTipoOperacao.getId();
        oEstoque.numeronota = txtNumeroNota.getInt();
        oEstoque.id_acessorio = cnsAcessorio.getId();
        oEstoque.id_tipoEmbalagem = cboTipoEmbalagem.getId();
        oEstoque.quantidade = txtQuantidade.getDouble();
        oEstoque.precoVenda = txtPrecoVenda.getDouble();
        oEstoque.prateleira = txtPrateleira.getText();
        oEstoque.utilizaporcentagem = Global.getParametro(1).getBoolean();

        double estoquemax = beanEstoque.verificaEstoqueMaximo(oEstoque.id_acessorio);
        if (estoquemax < (oEstoque.quantidade + txtEstoqueAtual.getDouble())) {
            Util.exibirMensagemConfirmar("Deseja Alterar o Estoque máximo do acessorio para " + (oEstoque.quantidade + txtEstoqueAtual.getDouble()), title);
            beanEstoque.atualizaEstoqueMaximo(oEstoque.id_acessorio, (oEstoque.quantidade + txtEstoqueAtual.getDouble()));
        }
        
        beanEstoque.salvarAcessorioEstoque(oEstoque);

        if (cboTipoOperacao.getId() == tipoOperacao.ENTRADA.getId()) {
            beanEstoque.atualizaAcessorioAutomacaoEntrada(oEstoque);
        }

        if (cboTipoOperacao.getId() == tipoOperacao.SAIDA.getId()) {
            if (txtEstoqueAtual.getDouble() != 0) {
                beanEstoque.atualizaAcessorioAutomacaoSaida(oEstoque);
            } else {
                throw new LBException("Estoque Zerado");
            }

            if (txtQuantidade.getDouble() > txtEstoqueAtual.getDouble()) {
                txtQuantidade.requestFocusLater();
                throw new LBException("Quantidade de saida maior que quantidade em estoque");
            }
        }
        Util.exibirMensagem(Util.MSG_SALVO_SUCESSO, getTitle());

        getEstadoTelaInicial();
    }

    public void carregarAcessorio(int i_id) throws Exception {
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        vRToolBarPadrao1 = new lbframework.bean.toolBarPadrao.LBToolBarPadrao(this);
        vRPanel2 = new lbframework.bean.panel.LBPanel();
        btnSair = new lbframework.bean.button.LBButton();
        btnSalvar = new lbframework.bean.button.LBButton();
        vRPanel1 = new lbframework.bean.panel.LBPanel();
        vRLabel1 = new lbframework.bean.label.LBLabel();
        cnsAcessorio = new lbframework.bean.consultaCampo.LBConsultaCampo();
        lblQtd = new lbframework.bean.label.LBLabel();
        txtQuantidade = new lbframework.bean.textField.LBTextField();
        vRLabel4 = new lbframework.bean.label.LBLabel();
        txtData = new lbframework.bean.calendar.LBCalendar();
        vRLabel6 = new lbframework.bean.label.LBLabel();
        cboTipoOperacao = new lbframework.bean.comboBox.LBComboBox();
        vRLabel9 = new lbframework.bean.label.LBLabel();
        txtNumeroNota = new lbframework.bean.textField.LBTextField();
        cboTipoEmbalagem = new lbframework.bean.comboBox.LBComboBox();
        vRLabel10 = new lbframework.bean.label.LBLabel();
        txtPrateleira = new lbframework.bean.textField.LBTextField();
        lblcusto1 = new lbframework.bean.label.LBLabel();
        vRPanel3 = new lbframework.bean.panel.LBPanel();
        vRLabel7 = new lbframework.bean.label.LBLabel();
        txtEstoqueAtual = new lbframework.bean.textField.LBTextField();
        vRLabel8 = new lbframework.bean.label.LBLabel();
        txtCustoAtual = new lbframework.bean.textField.LBTextField();
        txtPrecoVenda = new lbframework.bean.textField.LBTextField();
        lblcusto = new lbframework.bean.label.LBLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Estoque Acessorio Cadastro");
        addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                formInternalFrameClosing(evt);
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        vRToolBarPadrao1.setRollover(true);
        vRToolBarPadrao1.setVisibleParametrizar(true);
        vRToolBarPadrao1.setVisibleSalvar(true);

        btnSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/lbframework/img/sair.png"))); // NOI18N
        btnSair.setText("Sair");
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });

        btnSalvar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/lbframework/img/salvar.png"))); // NOI18N
        btnSalvar.setText("Salvar");
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout vRPanel2Layout = new javax.swing.GroupLayout(vRPanel2);
        vRPanel2.setLayout(vRPanel2Layout);
        vRPanel2Layout.setHorizontalGroup(
            vRPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, vRPanel2Layout.createSequentialGroup()
                .addContainerGap(322, Short.MAX_VALUE)
                .addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnSair, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        vRPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnSair, btnSalvar});

        vRPanel2Layout.setVerticalGroup(
            vRPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(vRPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(btnSair, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(btnSalvar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        vRLabel1.setText("Acessório");

        cnsAcessorio.addEventoConsultaCampoListener(new lbframework.bean.consultaCampo.LBEventoConsultaCampoListener() {
            public void abreTelaConsulta(lbframework.bean.consultaCampo.LBEventoConsultaCampo evt) {
                cnsAcessorioAbreTelaConsulta(evt);
            }
            public void aposConsulta(lbframework.bean.consultaCampo.LBEventoConsultaCampo evt) {
                cnsAcessorioAposConsulta(evt);
            }
        });

        lblQtd.setText("Quantidade");

        txtQuantidade.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
        txtQuantidade.setMascara("Numero");
        txtQuantidade.setObrigatorio(true);
        txtQuantidade.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                txtQuantidadeFocusLost(evt);
            }
        });

        vRLabel4.setText("Data ");

        txtData.setObrigatorio(true);

        vRLabel6.setText("Tipo Operação");

        vRLabel9.setText("Numero Nota");

        txtNumeroNota.setMascara("Numero");

        vRLabel10.setText("Tipo Embalagem");

        txtPrateleira.setColumns(10);

        lblcusto1.setText("Prateleira");

        javax.swing.GroupLayout vRPanel1Layout = new javax.swing.GroupLayout(vRPanel1);
        vRPanel1.setLayout(vRPanel1Layout);
        vRPanel1Layout.setHorizontalGroup(
            vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(vRPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(vRPanel1Layout.createSequentialGroup()
                        .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(vRLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtData, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(vRPanel1Layout.createSequentialGroup()
                                .addGap(280, 280, 280)
                                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(cboTipoEmbalagem, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                                    .addComponent(vRLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addGroup(vRPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(cboTipoOperacao, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                                    .addComponent(vRLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(txtNumeroNota, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(vRLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addComponent(cnsAcessorio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(vRLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(vRPanel1Layout.createSequentialGroup()
                        .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtQuantidade, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblQtd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtPrateleira, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblcusto1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        vRPanel1Layout.setVerticalGroup(
            vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(vRPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(vRPanel1Layout.createSequentialGroup()
                        .addComponent(vRLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cboTipoEmbalagem, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(vRPanel1Layout.createSequentialGroup()
                        .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(vRPanel1Layout.createSequentialGroup()
                                .addComponent(vRLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtNumeroNota, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(vRPanel1Layout.createSequentialGroup()
                                .addComponent(vRLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(vRPanel1Layout.createSequentialGroup()
                                .addComponent(vRLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cboTipoOperacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(vRLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cnsAcessorio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(vRPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(vRPanel1Layout.createSequentialGroup()
                        .addComponent(lblQtd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtQuantidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(vRPanel1Layout.createSequentialGroup()
                        .addComponent(lblcusto1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPrateleira, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        vRLabel7.setText("Estoque Atual");

        txtEstoqueAtual.setEnabled(false);
        txtEstoqueAtual.setMascara("Decimal 3");

        vRLabel8.setText("Preço Custo");

        txtCustoAtual.setEnabled(false);
        txtCustoAtual.setMascara("Numero");

        txtPrecoVenda.setEnabled(false);
        txtPrecoVenda.setMascara("Decimal 3");

        lblcusto.setText("Preço Venda");

        javax.swing.GroupLayout vRPanel3Layout = new javax.swing.GroupLayout(vRPanel3);
        vRPanel3.setLayout(vRPanel3Layout);
        vRPanel3Layout.setHorizontalGroup(
            vRPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(vRPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(vRPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtEstoqueAtual, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(vRLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(vRPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(vRLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCustoAtual, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(vRPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtPrecoVenda, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblcusto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(223, Short.MAX_VALUE))
        );
        vRPanel3Layout.setVerticalGroup(
            vRPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(vRPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(vRPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(vRPanel3Layout.createSequentialGroup()
                        .addComponent(lblcusto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPrecoVenda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(vRPanel3Layout.createSequentialGroup()
                        .addGroup(vRPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(vRLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(vRLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(vRPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtEstoqueAtual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtCustoAtual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(vRPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(vRToolBarPadrao1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(vRPanel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(vRPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(vRToolBarPadrao1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(vRPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(vRPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(vRPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
        try {
            verificarAlteracaoTela();
            sair();

        } catch (Exception ex) {
            Util.exibirMensagemErro(ex, getTitle());
        }
    }//GEN-LAST:event_btnSairActionPerformed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
        try {
            salvar();
            
        } catch (Exception ex) {
            Util.exibirMensagemErro(ex, getTitle());
        }
    }//GEN-LAST:event_btnSalvarActionPerformed

    private void cnsAcessorioAposConsulta(lbframework.bean.consultaCampo.LBEventoConsultaCampo evt) {//GEN-FIRST:event_cnsAcessorioAposConsulta
        try {
            if (cnsAcessorio.getInt("id_tipoembalagem") == tipoEmbalagem.KG.getId()) {
                txtCustoAtual.setMascara("Decimal 2");
                lblQtd.setText("Qtd. (g)");
                lblcusto.setText("Preço Venda por Kilo");
                txtQuantidade.setMascara("Decimal 3");
                txtPrecoVenda.setMascara("Decimal 2");
                txtEstoqueAtual.setMascara("Decimal 3");
            } else {
                txtCustoAtual.setMascara("Decimal 3");
                lblQtd.setText("Quantidade");
                lblcusto.setText("Preço Venda");
                txtQuantidade.setMascara("Decimal 0");
                txtPrecoVenda.setMascara("Decimal 3");
                txtEstoqueAtual.setMascara("Decimal 0");
            }
            txtCustoAtual.setDouble(cnsAcessorio.getDouble("precounitario"));
            cboTipoEmbalagem.setId(cnsAcessorio.getInt("id_tipoembalagem"));

            //Atualiza Estoque Atual
            oEstoque.quantidadeAtual = beanEstoque.verificaEstoque(cnsAcessorio.getId());
            txtEstoqueAtual.setDouble(oEstoque.quantidadeAtual);

            //Atualiza Campo Preço Venda
            atualizaPrecoVenda();
            txtPrecoVenda.setDouble(oEstoque.precoVenda);


            oEstoque.achou = beanEstoque.verificaPrateleira(cnsAcessorio.getId());
            if (oEstoque.achou) {
                txtPrateleira.setText(beanEstoque.carregarPrateleira(cnsAcessorio.getId()));
                txtPrateleira.setEnabled(false);
            }
            if (!(oEstoque.achou)) {
                txtPrateleira.setText("");
                txtPrateleira.setEnabled(true);
            }




        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        }

    }//GEN-LAST:event_cnsAcessorioAposConsulta

    @Override
    public void parametrizar() throws Exception {


        ParametroGUI form = new ParametroGUI(mdiFrame);

        form.carregarParametro(1, 2);
        form.setVisible(true);
    }

    public void atualizaPrecoVenda() throws Exception {

        if (Global.getParametro(1).getBoolean()) {
            oEstoque.precoVenda = txtCustoAtual.getDouble() + (txtCustoAtual.getDouble() * (Global.getParametro(2).getDouble() / 100));
        } else {
            oEstoque.precoVenda = txtCustoAtual.getDouble();
        }

    }

    private void cnsAcessorioAbreTelaConsulta(lbframework.bean.consultaCampo.LBEventoConsultaCampo evt) {//GEN-FIRST:event_cnsAcessorioAbreTelaConsulta

        try {
            MenuGUI menu = (MenuGUI) mdiFrame;

            if (menu.formAcessorioConsulta == null || menu.formAcessorioConsulta.isClosed()) {
                menu.formAcessorioConsulta = new AcessorioConsultaGUI(mdiFrame);
            }

            menu.formAcessorioConsulta.setConsultaCampo(cnsAcessorio);
            menu.formAcessorioConsulta.setVisible(true);

        } catch (Exception ex) {
            Util.exibirMensagemErro(ex, getTitle());
        }
    }//GEN-LAST:event_cnsAcessorioAbreTelaConsulta

    private void txtQuantidadeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtQuantidadeFocusLost
        try {
            if (cboTipoOperacao.getId() == tipoOperacao.SAIDA.getId()) {
                if (!(txtQuantidade.getText().equals(""))) {
                    if (txtEstoqueAtual.getDouble() == 0) {
                        Util.exibirMensagem("Estoque Zerado", null);
                    }
                }
                if (txtEstoqueAtual.getDouble() != 0 && txtQuantidade.getDouble() > txtEstoqueAtual.getDouble()) {
                    txtQuantidade.requestFocusLater();
                    Util.exibirMensagem("Quantidade de saida maior que quantidade em estoque", null);
                }
            } else {
            }
        } catch (Exception ex) {
            Exceptions.printStackTrace(ex);
        }

    }//GEN-LAST:event_txtQuantidadeFocusLost

    private void formInternalFrameClosing(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_formInternalFrameClosing
        try {
            verificarAlteracaoTela();
            sair();
            
        } catch (Exception e) {
            Util.exibirMensagemErro(e, getTitle());
        }
    }//GEN-LAST:event_formInternalFrameClosing

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private lbframework.bean.button.LBButton btnSair;
    private lbframework.bean.button.LBButton btnSalvar;
    private lbframework.bean.comboBox.LBComboBox cboTipoEmbalagem;
    private lbframework.bean.comboBox.LBComboBox cboTipoOperacao;
    private lbframework.bean.consultaCampo.LBConsultaCampo cnsAcessorio;
    private lbframework.bean.label.LBLabel lblQtd;
    private lbframework.bean.label.LBLabel lblcusto;
    private lbframework.bean.label.LBLabel lblcusto1;
    private lbframework.bean.textField.LBTextField txtCustoAtual;
    private lbframework.bean.calendar.LBCalendar txtData;
    private lbframework.bean.textField.LBTextField txtEstoqueAtual;
    private lbframework.bean.textField.LBTextField txtNumeroNota;
    private lbframework.bean.textField.LBTextField txtPrateleira;
    private lbframework.bean.textField.LBTextField txtPrecoVenda;
    private lbframework.bean.textField.LBTextField txtQuantidade;
    private lbframework.bean.label.LBLabel vRLabel1;
    private lbframework.bean.label.LBLabel vRLabel10;
    private lbframework.bean.label.LBLabel vRLabel4;
    private lbframework.bean.label.LBLabel vRLabel6;
    private lbframework.bean.label.LBLabel vRLabel7;
    private lbframework.bean.label.LBLabel vRLabel8;
    private lbframework.bean.label.LBLabel vRLabel9;
    private lbframework.bean.panel.LBPanel vRPanel1;
    private lbframework.bean.panel.LBPanel vRPanel2;
    private lbframework.bean.panel.LBPanel vRPanel3;
    private lbframework.bean.toolBarPadrao.LBToolBarPadrao vRToolBarPadrao1;
    // End of variables declaration//GEN-END:variables
}
